﻿Imports Microsoft.Win32

Public Class Form1
    Dim memory As New Softie.Memory___.Memory
    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        memory.Defrag(True)
    End Sub
    Dim MenTotal As String = My.Computer.Info.TotalPhysicalMemory
    Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick

        If MyBase.WindowState = FormWindowState.Minimized Then
            PictureBox1.Visible = False
            ProgressBar1.Visible = False
            Label1.Visible = False
            Label2.Visible = False
            Label3.Visible = False
            Label4.Visible = False
            Label5.Visible = False
            MyBase.ShowInTaskbar = False
            MyBase.FormBorderStyle = Windows.Forms.FormBorderStyle.None
            MyBase.TransparencyKey = MyBase.BackColor

        End If

        Dim MemFree As String = My.Computer.Info.AvailablePhysicalMemory


        ProgressBar1.Maximum = MenTotal
        ProgressBar1.Value = MemFree
        Label5.Text = "Free Memory : " & MemFree
    End Sub

    Private Sub Label3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label3.Click
        If Label3.Text = "On" Then
            Timer1.Enabled = False
            Label3.Text = "Off"
            OnToolStripMenuItem.Text = "Off"
            Label3.ForeColor = Color.Red
            OnToolStripMenuItem.ForeColor = Color.Red
            NotifyIcon1.Text = "Off"
            PictureBox1.ImageLocation = Application.StartupPath & "\off.png"
        Else
            PictureBox1.ImageLocation = Application.StartupPath & "\on.png"
            Timer1.Enabled = True
            Label3.Text = "On"
            OnToolStripMenuItem.Text = "On"
            Label3.ForeColor = Color.LimeGreen
            OnToolStripMenuItem.ForeColor = Color.LimeGreen
            NotifyIcon1.Text = "On"
        End If

    End Sub



    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        ProgressBar1.Visible = False
        PictureBox1.Visible = False
        Label1.Visible = False
        Label2.Visible = False
        Label3.Visible = False
        Label4.Visible = False
        Label5.Visible = False
        MyBase.ShowInTaskbar = False
        MyBase.FormBorderStyle = Windows.Forms.FormBorderStyle.None
        MyBase.TransparencyKey = MyBase.BackColor
        GetRegistro()
    End Sub

    Private Sub OnToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OnToolStripMenuItem.Click
        If Label3.Text = "On" Then
            Timer1.Enabled = False
            Label3.Text = "Off"
            OnToolStripMenuItem.Text = "Off"
            Label3.ForeColor = Color.Red
            OnToolStripMenuItem.ForeColor = Color.Red
            NotifyIcon1.Text = "Off"
        Else
            Timer1.Enabled = True
            Label3.Text = "On"
            OnToolStripMenuItem.Text = "On"
            Label3.ForeColor = Color.LimeGreen
            OnToolStripMenuItem.ForeColor = Color.LimeGreen
            NotifyIcon1.Text = "On"
        End If
    End Sub

    Private Sub ConfigurerToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ConfigurerToolStripMenuItem.Click
        MyBase.WindowState = FormWindowState.Normal
        ProgressBar1.Visible = True
        PictureBox1.Visible = True
        Label1.Visible = True
        Label2.Visible = True
        Label3.Visible = True
        Label4.Visible = True
        Label5.Visible = True
        MyBase.ShowInTaskbar = True
        MyBase.FormBorderStyle = Windows.Forms.FormBorderStyle.Sizable
        MyBase.TransparencyKey = Color.BurlyWood

    End Sub

  

    Private Sub ExitToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitToolStripMenuItem.Click
        Application.Exit()
    End Sub

    Private Sub Registro(ByVal Path As String)
        Dim regKey As RegistryKey
        regKey = Registry.CurrentUser.OpenSubKey("Software\Microsoft\Windows\CurrentVersion\Run", True)
        regKey.SetValue("Memory", Path)
    End Sub

    Private Sub GetRegistro()
        Dim path As String
        Dim regKey As RegistryKey
        regKey = Registry.CurrentUser.OpenSubKey("Software\Microsoft\Windows\CurrentVersion\Run", True)
        Path = regKey.GetValue("Memory")

        If Path = Application.StartupPath & "\" & My.Application.Info.AssemblyName Then

        Else
            Registro(Application.StartupPath & "\" & My.Application.Info.AssemblyName)
        End If
    End Sub

    Private Sub AboutToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AboutToolStripMenuItem.Click
        MsgBox("Developed by : Jucelio A. Alencar" & vbNewLine & "GNU General Public License (GPL) Software")
    End Sub

    Private Sub Label4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label4.Click
        Process.Start("http://softie.com.br")
    End Sub
End Class
